#!/bin/bash

# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

# deb opensearch-dashboards postinst script

set -e

echo "Running OpenSearch-Dashboards Post-Installation Script"

product_dir=/usr/share/opensearch-dashboards
config_dir=/etc/opensearch-dashboards
data_dir=/var/lib/opensearch-dashboards
log_dir=/var/log/opensearch-dashboards
pid_dir=/var/run/opensearch-dashboards

# Reload systemctl daemon
if command -v systemctl > /dev/null; then
    systemctl daemon-reload
fi

# Reload other configs
if command -v systemd-tmpfiles > /dev/null; then
    systemd-tmpfiles --create opensearch-dashboards.conf
fi

# Messages
echo "### NOT starting on installation, please execute the following statements to configure opensearch-dashboards service to start automatically using systemd"
echo " sudo systemctl daemon-reload"
echo " sudo systemctl enable opensearch-dashboards.service"
echo "### You can start opensearch-dashboards service by executing"
echo " sudo systemctl start opensearch-dashboards.service"
echo "### Upcoming breaking change in packaging"
echo " In a future release of OpenSearch Dashboards, we plan to change the permissions associated with access to installed files"
echo " If you are configuring tools that require read access to the OpenSearch Dashboards configuration files, we recommend you add the user that runs these tools to the 'opensearch-dashboards' group"
echo " For more information, see https://github.com/opensearch-project/opensearch-build/pull/4043"

# Set owner
chown -R opensearch-dashboards:opensearch-dashboards ${product_dir}
chown -R opensearch-dashboards:opensearch-dashboards ${config_dir}
chown -R opensearch-dashboards:opensearch-dashboards ${log_dir}
chown -R opensearch-dashboards:opensearch-dashboards ${data_dir}
chown -R opensearch-dashboards:opensearch-dashboards ${pid_dir}

exit 0


